<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学生编号" prop="stuSn">
        <el-input
          v-model="queryParams.stuSn"
          placeholder="请输入学生编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学生名称" prop="stuName">
        <el-input
          v-model="queryParams.stuName"
          placeholder="请输入学生名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="现班级名称" prop="className">
        <el-select v-model="queryParams.className" placeholder="请选择现班级名称" clearable>
          <el-option
            v-for="dict in dict.type.bbl_grade"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="老师id" prop="teacherId">
        <el-input
          v-model="queryParams.teacherId"
          placeholder="请输入老师id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="老师名称" prop="teacherName">
        <el-select v-model="queryParams.teacherName" placeholder="请选择老师名称" clearable>
          <el-option
            v-for="dict in dict.type.bbl_teacher"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="困难系数" prop="difficultyCoefficient">
        <el-select v-model="queryParams.difficultyCoefficient" placeholder="请选择困难系数" clearable>
          <el-option
            v-for="dict in dict.type.bbl_degree_difficulty"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="模拟面试" prop="interviewTest">
        <el-select v-model="queryParams.interviewTest" placeholder="请选择模拟面试" clearable>
          <el-option
            v-for="dict in dict.type.bbl_interview_test"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="结业考试" prop="finalTest">
        <el-select v-model="queryParams.finalTest" placeholder="请选择结业考试" clearable>
          <el-option
            v-for="dict in dict.type.bbl_interview_test"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="现班级ID" prop="newClassId">
        <el-input
          v-model="queryParams.newClassId"
          placeholder="请输入现班级ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['student:Studentrepeaterlog:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['student:Studentrepeaterlog:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['student:Studentrepeaterlog:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['student:Studentrepeaterlog:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="StudentrepeaterlogList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键id(留级表)" align="center" prop="id" />
      <el-table-column label="学生编号" align="center" prop="stuSn" />
      <el-table-column label="学生名称" align="center" prop="stuName" />
      <el-table-column label="现班级名称" align="center" prop="className">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.bbl_grade" :value="scope.row.className"/>
        </template>
      </el-table-column>
      <el-table-column label="老师id" align="center" prop="teacherId" />
      <el-table-column label="老师名称" align="center" prop="teacherName">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.bbl_teacher" :value="scope.row.teacherName"/>
        </template>
      </el-table-column>
      <el-table-column label="困难系数" align="center" prop="difficultyCoefficient">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.bbl_degree_difficulty" :value="scope.row.difficultyCoefficient"/>
        </template>
      </el-table-column>
      <el-table-column label="模拟面试" align="center" prop="interviewTest">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.bbl_interview_test" :value="scope.row.interviewTest"/>
        </template>
      </el-table-column>
      <el-table-column label="结业考试" align="center" prop="finalTest">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.bbl_interview_test" :value="scope.row.finalTest"/>
        </template>
      </el-table-column>
      <el-table-column label="现班级ID" align="center" prop="newClassId" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['student:Studentrepeaterlog:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['student:Studentrepeaterlog:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-set-up"
            @click="handleTrackDetails(scope.row)"
          >跟踪记录</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改留级表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="学生编号" prop="stuSn">
          <el-input v-model="form.stuSn" placeholder="请输入学生编号" />
        </el-form-item>
        <el-form-item label="学生名称" prop="stuName">
          <el-input v-model="form.stuName" placeholder="请输入学生名称" />
        </el-form-item>
        <el-form-item label="现班级名称" prop="className">
          <el-select v-model="form.className" placeholder="请选择现班级名称">
            <el-option
              v-for="dict in dict.type.bbl_grade"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="老师id" prop="teacherId">
          <el-input v-model="form.teacherId" placeholder="请输入老师id" />
        </el-form-item>
        <el-form-item label="老师名称" prop="teacherName">
          <el-select v-model="form.teacherName" placeholder="请选择老师名称">
            <el-option
              v-for="dict in dict.type.bbl_teacher"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="困难系数" prop="difficultyCoefficient">
          <el-select v-model="form.difficultyCoefficient" placeholder="请选择困难系数">
            <el-option
              v-for="dict in dict.type.bbl_degree_difficulty"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="模拟面试" prop="interviewTest">
          <el-select v-model="form.interviewTest" placeholder="请选择模拟面试">
            <el-option
              v-for="dict in dict.type.bbl_interview_test"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="结业考试" prop="finalTest">
          <el-select v-model="form.finalTest" placeholder="请选择结业考试">
            <el-option
              v-for="dict in dict.type.bbl_interview_test"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="现班级ID" prop="newClassId">
          <el-input v-model="form.newClassId" placeholder="请输入现班级ID" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 跟踪详情 -->
    <el-dialog :title="title" :visible.sync="open1" width="500px" append-to-body>
      <el-form ref="form" :model="repeatTrack" :rules="rules" label-width="80px">
        <el-form-item label="学生名称" prop="stuName">
          <el-input v-model="repeatTrack.stuName" :disabled="true" placeholder="请输入学生名称" />
        </el-form-item>
        <el-form-item label="学生id" v-show=false  prop="stuSn">
          <el-input v-model="repeatTrack.stuSn" :disabled="true" placeholder="请输入学生名称" />
        </el-form-item>
        <el-form-item label="任务日期" prop="taskDate">
          <el-date-picker clearable
                          v-model="repeatTrack.taskDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择任务日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="任务状态" prop="taskStatus">
          <el-select v-model="repeatTrack.taskStatus" placeholder="请选择任务状态">
            <el-option
              v-for="dict in dict.type.bbl_task_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="任务说明" prop="taskExplain">
          <el-input v-model="repeatTrack.taskExplain" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-button type="primary"   @click="submitStudenttrack">添加任务</el-button>
        <el-button @click="cancel">取 消</el-button>
      </el-form>

      <div class="block" >
        <el-timeline v-for="details in trackDetails">
          <el-timeline-item :timestamp=details.taskDate placement="top">
            <el-card>
              <h4>跟踪人【{{details.teacherName}}】</h4>
              <p>情况说明:{{details.taskExplain}}</p >
              <!--<p>完成说明:{{details.taskStatus}}</p >-->
            </el-card>
          </el-timeline-item>
          <!--<el-form-item label="任务状态" prop="details.taskStatus">
            <el-select v-model="details.taskStatus" placeholder="请选择任务状态">
              <el-option
                v-for="details in dict.type.bbl_task_status"
                :key="details.value"
                :label="details.label"
                :value="details.value"
              ></el-option>
            </el-select>
          </el-form-item>-->
        </el-timeline>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listStudentrepeaterlog, getStudentrepeaterlog, delStudentrepeaterlog, addStudentrepeaterlog, updateStudentrepeaterlog } from "@/api/student/Studentrepeaterlog";
import { getTaskstuSn , delTask, addTask, updateTask ,saveTask } from "@/api/student/task";

export default {
  name: "Studentrepeaterlog",
  dicts: ['bbl_teacher', 'bbl_degree_difficulty', 'bbl_grade', 'bbl_interview_test', 'bbl_task_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 留级表表格数据
      StudentrepeaterlogList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      open1: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        stuSn: null,
        stuName: null,
        className: null,
        teacherId: null,
        teacherName: null,
        difficultyCoefficient: null,
        interviewTest: null,
        finalTest: null,
        newClassId: null
      },
      // 跟踪详情
      trackDetails: [],
      //添加跟踪
      repeatTrack:{
        stuSn: null,
        stuName:null,
        taskDate: null,
        taskStatus: null,
        taskExplain: null,
        teacherName: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询留级表列表 */
    getList() {
      this.loading = true;
      listStudentrepeaterlog(this.queryParams).then(response => {
        this.StudentrepeaterlogList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.open1 = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        stuSn: null,
        stuName: null,
        className: null,
        teacherId: null,
        teacherName: null,
        difficultyCoefficient: null,
        interviewTest: null,
        finalTest: null,
        newClassId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加留级表";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getStudentrepeaterlog(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改留级表";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateStudentrepeaterlog(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStudentrepeaterlog(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 添加跟踪 */
    submitStudenttrack(){
      saveTask(this.repeatTrack).then(res => {
        this.$modal.msgSuccess("信息修改成功");
        this.open1 = false;
        this.getList();
      })
    },
    /** 跟踪详情 */
    handleTrackDetails(row){
      this.open1 = true;
      console.log(row.stuSn);
      this.title = row.stuName + "的任务历史";
      this.repeatTrack.stuName = row.stuName;
      this.repeatTrack.stuSn = row.stuSn;
      getTaskstuSn(row.stuSn).then(res => {
        this.trackDetails = res.data;
        console.log(res);
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除留级表编号为"' + ids + '"的数据项？').then(function() {
        return delStudentrepeaterlog(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('student/Studentrepeaterlog/export', {
        ...this.queryParams
      }, `Studentrepeaterlog_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
